package com.taofuxn.yycreazy.mvp.presenter;

import android.util.Log;

import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.model.VchatBean;
import com.taofuxn.yycreazy.mvp.view.IVchatView;
import com.taofuxn.yycreazy.retrofit.ApiStore;
import com.taofuxn.yycreazy.retrofit.Key;
import com.taofuxn.yycreazy.rxjava.ApiCallback;
import com.taofuxn.yycreazy.rxjava.SubscriberCallback;

import java.util.HashMap;

/**
 * Created by taofuxn on 2016/9/24.
 */
public class VchatPresenter extends BasePresenter {
    private IVchatView mIVchatView;

    public VchatPresenter(IVchatView mIVchatView){
        this.onAttachView(mIVchatView);
        this.mIVchatView = mIVchatView;
    }


    public void getVchatList(final int cur, final boolean isReflash){
        HashMap<String ,String> params = new HashMap<>();
        params.put("key", Key.vcKey);
        params.put("pno",""+cur);
        params.put("ps","20");
        addSubscription(mRetrofit.create(ApiStore.class).queryVChatList("http://v.juhe.cn/weixin/query",params),new SubscriberCallback(new ApiCallback<VchatBean>() {
            @Override
            public void onCompleted() {
            }
            @Override
            public void onFailed(int code, String msg) {
                mIVchatView.dismissLoading();
            }

            @Override
            public void onSuccess(VchatBean vchatBean) {
                Log.i("AAA","vchat="+vchatBean.result.totalPage+"  "+vchatBean.result.list.size());
                if (vchatBean.result.totalPage < cur){
                    mIVchatView.noMoreData();
                }
                if (isReflash) {
                    mIVchatView.requestSuccess(vchatBean.result.list);
                }else{
                    mIVchatView.loadmoreSuccess(vchatBean.result.list);
                }
                mIVchatView.dismissLoading();
            }
        }));

    }
}
